/**
 * @param {number} x
 * @return {number}
 */
 var reverse = function(x) {
    let result=0;
    let num=x.toString();
    if(num[0]=='-'){
        result=-Number(num.substr(1,num.length-1).split('').reverse().join(''));
    }else{
        result=Number(num.split('').reverse().join(''));
    }
    if(result>2147483647 || result<-2147483648){
        return 0;
    }
    else{
        return result;
    }
};

console.log(reverse(-56));